Cartographer ROS 学习

结合ROS利用Google开源的cartographer算法实时室内建图
Cartographer

学着踏实而务实,越努力越幸运。
当一个人有了足够的内涵和物质做后盾,人生就会变得底气十足。
若是美好,叫做精彩,若是糟糕,叫做经历。

Cartographer介绍

google开源中的介绍:
https://opensource.googleblog.com/2016/10/introducing-cartographer.html

ROS版本安装

ROS版本安装 https://google-cartographer-ros.readthedocs.io/en/latest/
里面有个编译完整版的和未编译版本:
链接: https://pan.baidu.com/s/1hWtI2ZH_CZbjNw2vHzSB1w 提取码: sv98
cartographer (亲测可行) 【要翻墙】
https://google-cartographer-ros.readthedocs.io/en/latest/

使用数据集

创客智造中的安装及修改方法:
https://www.ncnynl.com/archives/201801/2230.html
不同SLAM结果对比工具:
官方 https://google-cartographer.readthedocs.io/en/latest/evaluation.html
Cartographer ROS for TurtleBots:
https://google-cartographer-ros-for-turtlebots.readthedocs.io/en/latest/

报错

1.[错误]attempt to index global ‘SPARSE_POSE_GRAPH’ (a nil value)
[原因]SPARSE_POSE_GRAPH was renamed into POSE_GRAPH half a year ago. Please make sure you are running the latest version.
因此,我们在制作lua配置脚本时参考最新的例子

2.运行TB3的包的时候报错:

1
[FATAL] [1478966491.756783878]: F1113 00:01:31.000000 11761 sensor_bridge.cc:98] Check failed: sensor_to_tracking->translation().norm() < 1e-5 The IMU frame must be colocated with the tracking frame. Transforming linear acceleration into the tracking frame will otherwise be imprecise.

[原因]:IMU的话题虽然能够匹配上,但消息的坐标名字不对。
[解决方案]:打开:

1
2
home/catkin_ws/src/turtlebot3/turtlebot3_slam/
src/flat_world_imu_node.cpp

修改46行的IMU消息header:imu_out.header.frame_id="imu_link";

算法运行

1
2
3
4
5
6
7
roslaunch turtlebot3_gazebo turtlebot3_house.launch 
roslaunch cartographer_ros cartographer_demo_rplidar.launch
把configuration中的rplidar.lua中的
tracking_frame = "base_scan", --SLAM算法最终的帧(改成你的雷达的帧 rostopic echo /scans)
published_frame = "base_scan", --同上
provide_odom_frame = true,
odom_frame = "odom",

打开rviz 就可看到。关键点就是这里的雷达和里程计的frame对应。

节点依赖

launch文件中加载的节点和配置文件:

1
2
3
4
5
<node name="cartographer_node" pkg="cartographer_ros"  
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename rplidar.lua"
output="screen">

获取cartographer轨迹:

https://github.com/googlecartographer/cartographer_ros/issues/332

结合TB3运行

添加文件:

1
2
cartographer_ws/src/cartographer_ros/cartographer_ros/
configuration_files/rplidar.lua

复制如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
include "map_builder.lua"
include "trajectory_builder.lua"

options = {
map_builder = MAP_BUILDER,
trajectory_builder = TRAJECTORY_BUILDER,
map_frame = "map",
tracking_frame = "laser_link"
published_frame = "laser_link",
odom_frame = "odom",
provide_odom_frame = true,
use_odometry = false,
num_laser_scans = 1,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
num_point_clouds = 0,
lookup_transform_timeout_sec = 0.2,
submap_publish_period_sec = 0.3,
pose_publish_period_sec = 5e-3,
trajectory_publish_period_sec = 30e-3,

}
MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

SPARSE_POSE_GRAPH.optimization_problem.huber_scale = 1e2
SPARSE_POSE_GRAPH.optimize_every_n_scans = 35
SPARSE_POSE_GRAPH.constraint_builder.min_score = 0.65

return options

添加launch文件:

1
2
cartographer_ws/src/cartographer_ros/cartographer_ros/
launch/cartographer_demo_rplidar.launch

复制如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- 请复制该文件到cartographer_ros/cartographer_ros/launch中使用 -->

<launch>
<param name="/use_sim_time" value="true" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename rplidar.lua"
output="screen">
<remap from="scan" to="scan" />
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</launch>

重新编译 catkin_make_isolated –install –use-ninja

rqt_graph

参考链接:https://google-cartographer-ros.readthedocs.io

-------------本文结束 感谢阅读-------------
0%